//
//  FadTabBar.m
//  BuDeJie
//
//  Created by 许良 on 16/7/22.
//  Copyright © 2016年 fading. All rights reserved.
//

#import "FadTabBar.h"

@interface FadTabBar()
@property (nonatomic,weak) UIButton *publishBtn;

@end

@implementation FadTabBar
- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self == [super initWithFrame:frame]) {
            UIButton *publishBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [publishBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
            [publishBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateSelected];
            [self addSubview:publishBtn];
        self.publishBtn.size = self.publishBtn.currentBackgroundImage.size;
        self.publishBtn = publishBtn;
    }
    return  self;
}
- (void)layoutSubviews{
    
    [super layoutSubviews];
    CGFloat width = self.width;
    CGFloat height = self.height;
    self.publishBtn.size = self.publishBtn.currentBackgroundImage.size;
    
    
    
    self.publishBtn.center = CGPointMake(width*0.5, height*0.5);
    
    //设置其他tabBar
    CGFloat buttonY = 0;
    CGFloat buttonW = width / 5;
    CGFloat buttonH = height;
    NSInteger index = 0;
    for (UIView *button in self.subviews) {
        if (![button isKindOfClass:[UIControl class]] || button == self.publishBtn) continue;
        
        CGFloat buttonX = buttonW * ((index > 1)?(index + 1):index);
        button.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
        index ++;
    }
}

@end
